<template>
  <TitleCard :title="titleCard" :showMore="showMore">
    <div class="backStack-table-wrap backStack-transferEamil">
      <Table
        ref="table"
        :options="fields"
        :tableValue="tableValue"
        :customSlotOpt="slotOpt"
        :otherOpt="customOtherOpt"
        :rowSelection="null"
        @change="initTableValue"
        @actionClick="handlerActionClick"
      ></Table>
    </div>
    <EditModal
      v-if="isShowModal"
      @cancel="cancel"
      @addSuccess="addSuccess"
      :emails="emails"
      :id="id"
    ></EditModal>
  </TitleCard>
</template>

<script>
import Table from '../../components/table/index.vue'
import mixinsBackStack from '@/views/backstageSupport/mixins'
import { fields, slotOpt } from './configs/configs'
import EditModal from './components/editModal.vue'
import { getTransferEamilList } from '@/api/transferEamil.js'

export default {
  mixins: [mixinsBackStack],
  data() {
    return {
      slotOpt,
      fields,
      customOtherOpt: {
        pagination: {
          total: 0,
          pageNum: 1,
          pageSize: 10
        }
      },
      tableValue: [],
      isShowModal: false,
      emails: [],
      id:''
    }
  },
  components: {
    Table,
    EditModal
  },
  mounted() {
    this.initTableValue()
  },
  methods: {
    async initTableValue() {
      try {
        this.loadingTable(true) // 开启表格的加载动画
        const { rows, total } = await getTransferEamilList() // 请求表格数据接口
        const row = this.handlerDateFormat(rows) // 处理时间格式
        row.forEach(element => {
          element.emails = element.emails.split(",")
          element.emails = element.emails.join("<br>")
        });
        this.tableValue = row
        this.customOtherOpt.pagination.total = total
        this.initSelectedRowIds() // 清空勾选的选项
      } catch (error) {
        this.$apiStatusHandler(99, error.msg) // 请求异常，则全局轻提示
      } finally {
        this.loadingTable(false)
      }
    },
    edit(row) {
      this.emails = row.emails.split("<br>") //html格式转为弹框需要格式
      this.emails = this.emails.reduce((pre,cur)=>{
        pre.push({
          email:cur,
        })
        return pre
      },[])
      this.id = row.id
      this.isShowModal = true
    },
    cancel() {
      this.isShowModal = false
    },
    addSuccess() {
      this.isShowModal = false
      this.initTableValue()
    },
  }
}
</script>
